<?
/**
* Copyright (c) 2002-2007 BioWare Corp.
* http://www.bigdaddymonitor.org
*
* This file is part of the BigDaddy Monitoring
* program. It is free software distributed under
* the terms of the BSD License. It is ditributed
* in the hopes that it will be useful, but
* WITHOUT ANY WARRANTY; without event the implied
* warranty of MERCHANTABILITY or FITNESS FOR A
* PARTICULAR PURPOSE.
*
* The BSD License is available from:
* http://www.opensource.org/licenses/bsd-license.php
**/
$aIncidentServers = array();

if ($sType == "edit")
{
	$aIncident = $BigDaddyData->GetIncidentByID($_REQUEST["ID"]);
	$aResult = $BigDaddyData->GetServersByIncidentID($_REQUEST["ID"]);
	
	
	if (is_array($aResult))
	{
		foreach ($aResult as $aRow)
		{
			$aIncidentServers[] = $aRow["serverID"];
		}
	}
}


if ($aIncident["incidentStart"] == "")
{
	$aIncident["incidentStart"] = 99;
}

if ($aIncident["incidentEnd"] == "")
{
	$aIncident["incidentEnd"] = 99;
}
?>
<form name="f" action="query_incident.php" method="post">
<table border="0" cellpadding="3" cellspacing="0" class="incident" width="98%">
<thead>
<th colspan="2">Incident Report Form</th>
</thead>
<tr valign="top">
	<td class="field">
	Incident Title
	</td>
	<td>
	<input type="text" name="title" value="<?=$aIncident["title"];?>" id="fieldinput">
	</td>
</tr>
<tr valign="top">
	<td class="field">
	Affected Servers
	</td>
	<td>
	<?
	
	$aCriteria = array(
			"active" => -1
			);
			
	$aServers = $BigDaddyData->GetServers($aCriteria);
	$aServers = $aServers["aResults"];
	?>
	<select name="aServerID[]" multiple size="10" class="fieldselect">
	<?
	if (is_array($aServers))
	{
		foreach($aServers as $aRow)
		{
			if (in_array($aRow["serverID"], $aIncidentServers))
			{
				$s=" selected";
			}
			else
			{
				$s="";
			}
			?>
			<option value="<?=$aRow["serverID"];?>"<?=$s;?>><?=$aRow["hostname"];?></option>
			<?
		}
	}
	?>
	</select>
	</td>
</tr>
<tr valign="top">
	<td class="field">
	Incident Start
	</td>
	<td>
	<?=create_dateselect("startDay", "startMonth", "startYear", $aIncident["incidentStart"], 1, "startHour", "startMinute");?>
	</td>
</tr>
<tr valign="top">
	<td class="field">
	Incident End
	</td>
	<td>
	<?=create_dateselect("endDay", "endMonth", "endYear", $aIncident["incidentEnd"], 1, "endHour", "endMinute");?>
	</td>
</tr>
<tr valign="top">
	<td class="field" colspan="2" style="background-color: #eee">
	Description ("What went wrong?")
	</td>
</tr>
<tr>
	<td colspan="2">
	<textarea name="description" rows="10" cols="50" class="fieldtextarea"><?=$aIncident["description"];?></textarea>
	</td>
</tr>
<tr valign="top">
	<td class="field" colspan="2" style="background-color: #eee">
	Reasons ("Why?")
	</td>
</tr>
<tr>
	<td colspan="2">
	<textarea name="reasons" rows="10" cols="50" class="fieldtextarea"><?=$aIncident["reasons"];?></textarea>
	</td>
</tr>
<tr valign="top">
	<td class="field" colspan="2" style="background-color: #eee">
	Follow Up ("What next?")
	</td>
</tr>
<tr>
	<td colspan="2">
	<textarea name="followup" rows="10" cols="50" class="fieldtextarea"><?=$aIncident["followup"];?></textarea>
	</td>
</tr>
</table>

<div align="center">
<?
if ($sType == "add")
{
	?>
	<input type="hidden" name="action" value="addincident">
	<?
}
elseif ($sType == "edit")
{
	?>
	<input type="hidden" name="action" value="editincident">
	<input type="hidden" name="ID" value="<?=$_REQUEST["ID"];?>">
	<?
}

?>
</div>
</form>
